package io.renren.modules.bs.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import io.renren.modules.app.vo.ReportVo;
import io.renren.modules.bs.entity.BsPatientEntity;
import io.renren.modules.bs.vo.BsPatientTreeVo;
import io.renren.modules.bs.vo.PatientVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 
 * 
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2019-08-15 23:03:15
 */
@Mapper
public interface BsPatientDao extends BaseMapper<BsPatientEntity> {

    /**
     *
     * @param patientName
     * @return
     */
    @Select("SELECT dp.department_patient_id,pat.patient_name,dp.department_id FROM bs_department_patient dp\n" +
            "LEFT JOIN bs_patient pat  on dp.patient_id = pat.patient_id\n" +
            "WHERE   dp.is_leave = 0\n" +
            "and pat.patient_name like CONCAT('%',#{patientName},'%') ")
    List<PatientVo> getOnlineListByName(@Param("patientName") String patientName);

    @Select("SELECT dp.*,dpa.department_patient_id FROM bs_department_patient  dpa\n" +
            "LEFT JOIN bs_patient dp on dpa.patient_id = dp.patient_id\n" +
            "WHERE  dpa.is_leave = 0 and dpa.department_id =#{departmentId}  ")
    List<BsPatientTreeVo> getTreeData(@Param("departmentId") Long departmentId);

    @Select("SELECT edp.extract_detail_patient_id,dp.*,pat.patient_name,pat.id_number,pat.gender,dept.department_name,hosp.hospital_name from bs_extract_detail_patient edp\n" +
            "LEFT JOIN bs_department_patient dp on edp.department_patient_id = dp.department_patient_id\n" +
            "LEFT JOIN bs_patient pat on dp.patient_id = pat.patient_id\n" +
            "LEFT JOIN bs_department dept on dept.department_id = dp.department_id\n" +
            "LEFT JOIN bs_hospital hosp on hosp.hospital_id = dept.hospital_id\n" +
            "WHERE edp.is_done = 0 and dp.department_id = #{departmentId} order by edp.extract_detail_patient_id desc")
    List<ReportVo> getReportList(@Param("departmentId") Long departmentId);

    @Select("SELECT dp.*,pat.patient_name,pat.id_number,pat.gender,dept.department_name,hosp.hospital_name,dpi.patient_img,dpi.photograph_date FROM bs_department_patient_img dpi\n" +
            "LEFT JOIN bs_department_patient dp on dpi.department_patient_id = dp.department_patient_id\n" +
            "LEFT JOIN bs_department dept on dept.department_id = dp.department_id\n" +
            "LEFT JOIN bs_hospital hosp on hosp.hospital_id = dept.hospital_id\n" +
            "LEFT JOIN bs_patient pat on dp.patient_id = pat.patient_id\n" +
            "WHERE year(dpi.create_time)=year(now()) and month(dpi.create_time)=month(now()) and day(dpi.create_time)=day(now())\n" +
            "and dpi.img_type = 2 and dp.department_id = #{departmentId} order by dpi.department_patient_img_id desc")
    List<ReportVo> getDoneReportList(@Param("departmentId") Long departmentId);

    @Select("SELECT count(1) FROM bs_department_patient dp\n" +
            "LEFT JOIN bs_patient pat on dp.patient_id = pat.patient_id\n" +
            "WHERE dp.is_leave = 0 and pat.id_number = #{idNumber}")
    Integer countByIdNumber(@Param("idNumber") String idNumber);
}
